package 课设;

import jdk.nashorn.internal.runtime.regexp.joni.ast.StringNode;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class userJFrame extends JPanel {
    private JTextField username,password,email;
    private JTextField sex;
    private JTextField year;
    private JButton ok;
    private String user_name="";
    private String pass_word="";
    private String s="";
    private int age=0;
    private String e="";

    public userJFrame(int userId) throws SQLException {
        super();
        this.setBorder(new TitledBorder("user"));
        this.setLayout(new GridLayout(6,1));

        //添加组件
        //------begin------
        ResultSet set = new db().executeQuery("select * from users where userId="+userId);
        ResultSet set1 = new db().executeQuery("select * from detailed_user where userId="+userId);

        if(set.next() && set1.next()){
            user_name = set.getString("username");
            pass_word = set.getString("password");
            s = set1.getString("sex");
            e = set1.getString("email");
            age = set1.getInt("age");
        }
        //用户名
        username = new JTextField(user_name);
        this.add(username);
        //用户名
        password = new JTextField(pass_word);
        this.add(password);
        //性别
        sex = new JTextField(s);
        this.add(sex);
        //出生日期
        year = new JTextField(String.valueOf(age));
        this.add(year);

        //邮箱
        email = new JTextField(e);
        this.add(email);

        //按钮
        ok = new JButton("修改");
        this.add(ok);
    }
    public static void main(String[] agrs) throws SQLException {
        userJFrame w = new userJFrame(1);
        w.setVisible(true);
    }
}

